package com.zzptc.myk.a1022;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import org.w3c.dom.Text;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    ListView listView;
    List<Student> list_stu;
    private static final String TAG = "MainActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        listView =findViewById(R.id.lv_stus);
        list_stu = new ArrayList<>();
        for ( int i=0;i<100;i++){
            Student student = new Student(R.mipmap.ic_launcher, i, "姓名" + i, new Date() + "");
            list_stu.add(student);
        }
        for(Student s:list_stu){
            Log.d(TAG,s.getName());
        }
        MyAdapter myAdapter = new MyAdapter();
        listView.setAdapter(myAdapter);
    }
    class  MyAdapter extends BaseAdapter{
        @Override
        public int getCount() {
            return list_stu.size();
        }

        @Override
        public Object getItem(int i) {
            return null;
        }

        @Override
        public long getItemId(int i) {
            return 0;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            //要数据
            Student student = list_stu.get(i);

            //要界面
            View inflate = View.inflate(MainActivity.this, R.layout.item_stu, null);

            //要绑定数据
            ImageView iv_pic = inflate.findViewById(R.id.iv_pic);
            iv_pic.setImageResource(R.mipmap.ic_launcher);
            TextView tv_id=inflate.findViewById(R.id.tv_id);
            tv_id.setText(student.getId()+"");//要将整数转换成字符串
            TextView  tv_name= inflate.findViewById(R.id.tv_name);
            tv_name.setText(student.getName());
            TextView tv_date=inflate.findViewById(R.id.tv_date);
            tv_date.setText(student.getTime());
            return inflate;
        }
    }
}
